﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace DAL
{
    public class T_DepPower
    {
        public T_DepPower()
        { }
        /// <summary>
        /// 对部门权限进行设置,已有进行修改，没有进行添加
        /// </summary>
        /// <param name="depname">部门名</param>
        /// <param name="power">对应权限</param>
        /// <returns>受影响行数</returns>
        public int setPower(string depname, string power)
        {
            string sql = "select * from [T_DepPower] where depname='" + depname + "'";
            DataTable dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                sql = "update [T_DepPower] set [Power]='" + power + "' where id=" + dt.Rows[0]["id"].ToString();
            }
            else
            {
                sql = "insert into [IPR_OnlineExamSys_ZZ].[dbo].[T_DepPower](depname,[power]) values('"+depname+"','"+power+"')";
            }
            return DBUtility.DbHelperSQL.ExecuteSql(sql) ;
        }
        /// <summary>
        /// 通过部门名字得到对应权限
        /// </summary>
        /// <param name="depname">部门名字</param>
        /// <returns>返回权限编号例：008,007,006,001</returns>
        public string getPowerByDepName(string depname)
        {
            string sql = "select * from [T_DepPower] where depname='" + depname + "'";
            DataTable dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
            string strpower = "";
            if (dt.Rows.Count > 0)
            {
                strpower = dt.Rows[0]["Power"].ToString();
            }
            return strpower;
        }
    }
}
